package com.android.footprint.util;

import java.util.List;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;

public class LocUtil {
//  String str1 = LocationManager.GPS_PROVIDER;
//  String str2 = LocationManager.PASSIVE_PROVIDER;
//  String str3 = LocationManager.NETWORK_PROVIDER;
    
    private LocUtil() {
        
    }
    
    public static Location getLocation(Context cxt) {
        LocationManager locManager = (LocationManager) cxt.getSystemService(Context.LOCATION_SERVICE);
        List<String> providers_list = locManager.getAllProviders();
        for (String item : providers_list) {
            Location loc = locManager.getLastKnownLocation(item);
            if (loc != null) {
                return loc;
            }
        }
        return null;
    }
    
    public static void requestLocationUpdates(Context cxt, long minTime, float minDistance, LocationListener listener) {
        LocationManager locManager = (LocationManager) cxt.getSystemService(Context.LOCATION_SERVICE);
        List<String> providers_list = locManager.getAllProviders();
        for (String provider : providers_list) {
            locManager.requestLocationUpdates(provider, minTime, minDistance, listener);
        }
    }
}
